import api from '../api/index'
import axios from '../utils/axios'

const getAllVote = () => {
    return new Promise((resolve, reject) => {
        axios.get(api.voteApi.Vote_getAll)
            .then(res => {
                resolve(res.data)
            })
            .catch(err => reject(err))
    })
}

const updateVoteState = (id, state) => {
    return new Promise((resolve, reject) => {
        axios.post(api.voteApi.Vote_UpdateState, { id, state })
            .then(res => {
                resolve(res.data)
            })
            .catch(err => reject(err))
    })
}

const deleteVoteById = (id) => {
    return new Promise((resolve, reject) => {
        axios.post(api.voteApi.Vote_deleteById, { id })
            .then(res => {
                resolve(res.data)
            })
            .catch(err => reject(err))
    })
}

const getVoteById = (id) => {
    return new Promise((resolve, reject) => {
        axios.post(api.voteApi.Vote_getVoteById, { id })
            .then(res => {
                resolve(res.data)
            })
            .catch(err => reject(err))
    })
}

// title, scope, object, Publisher, explain1, option1, type, end, result
const addVote = (args) => {
    return new Promise((resolve, reject) => {
        axios.post(api.voteApi.Vote_addVote, args)
            .then(res => {
                resolve(res.data)
            })
            .catch(err => reject(err))
    })
}

export default {
    getAllVote,
    updateVoteState,
    deleteVoteById,
    getVoteById,
    addVote
}
